package lm.concurrency.day1;

import lm.concurrency.util.Sleeper;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.LockSupport;

/**
 * @Auther: Min.Liu
 * @Description:
 * @Date: Created in 9:04 2024/6/4
 */
@Slf4j
public class InterruptWithParkTest {

    private static void test1() {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                log.debug("park...");
                LockSupport.park();
                log.debug("打断状态：{}", Thread.currentThread().isInterrupted());
                log.debug("静态打断状态：{}", Thread.interrupted());
                log.debug("静态打断状态之后：{}", Thread.currentThread().isInterrupted());
            }
        });
        t1.start();


        Sleeper.sleep(1);
        t1.interrupt();
        Sleeper.sleep(1);
        t1.interrupt();
    }

    private static void test2() throws InterruptedException {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                log.debug("park...");
                LockSupport.park();
                log.debug("打断状态：{}", Thread.interrupted());
                //log.debug("打断状态：{}", Thread.currentThread().isInterrupted());
            }
        }, "t1");
        t1.start();

        Sleeper.sleep(1);
        t1.interrupt();

    }

    public static void main(String[] args) throws InterruptedException {
        test1();
    }
}
